import QtQuick 2.6
import QtQuick.Layouts 1.2
import QtQuick.Controls 1.4

import "../../../Base/UiBase"
import "../../../Base/Config"
import "../../../Base/UiBase/TC" as TC

import Code 1.0

import Cpp.Request 1.0 as Request

MouseArea {
    id: root

    property int groupId
    property string groupName
    property alias listView : listView

    Rectangle {
        anchors.fill: parent
        color: Color.background
    }

    ColumnLayout {
        anchors.fill: parent
        spacing: 0

        // header
        Rectangle {
            Layout.fillWidth: true
            Layout.preferredHeight: 96 * Size.ratio
            color: Color.foreground

            // back button
            MouseArea {
                width: parent.height
                height: parent.height

                onClicked: root.visible = false
                Rectangle {
                    anchors.fill: parent
                    color: Color.pressed
                    visible: parent.pressed
                }
                SvgzImage {
                    anchors.centerIn: parent
                    sourceSize.width: 80 * Size.ratio
                    sourceSize.height: 96 * Size.ratio
                    source: "../../../../resources/comment/fanhiu01.svg"
                }
            } // end back button

            // title
            Text {
                text: groupName
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                font.pixelSize: Size.titleFont
            } // end title
            BottomDivider {
            }
        } // end header

        ListView {
            id: listView
            Layout.fillWidth: true
            Layout.fillHeight: true

            spacing: 0
            model: ListModel {
                id: listModel
            }
        }
    } // end ColumnLayout

    onGroupIdChanged: {
        newsQuery.queryAll(groupId)
    }

    Request.NewsQuery {
        id: newsQuery
        onOk: {
            listModel.clear()
            for (var i in news) {
                listModel.append(news[i])
            }
        }
    }
}
